<?xml version='1.0' encoding='UTF-8' ?>
<ui:composition template="template-with-sidebar.xhtml" xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ice="http://www.icesoft.com/icefaces/component"
                xmlns:odr="http://java.sun.com/jsf/composite/odr">

    <ui:define name="head">
        <ui:insert name="pagetitle" />
    </ui:define>

    <ui:define name="pagetitle">
        <ui:insert name="pagetitle" />
    </ui:define>

    <ui:define name="content">

        <ice:panelGroup rendered="#{!manageProjectController.validRequest}" >
            <h1><ice:outputText value="#{form['project.manage.no.project.selected.title']}" /></h1>
            <ice:outputText value="#{form['project.manage.no.project.selected.text']}"  />
        </ice:panelGroup>

        <odr:breadcrumb breadCrumbSource="#{manageProjectController.navigationBar}" />

        <ice:form id="deleteConfirmForm" rendered="#{manageProjectController.validRequest and manageProjectController.deleteRequest}">
            <h1><ui:insert name="heading" /></h1>

            <p class="deleteConfirmationMessage">
            <ui:insert name="deleteConfirmationText" />
            </p>

            <ice:commandButton action="#{manageProjectController.delete}"
                               value="#{form['button.delete']}"
                               styleClass="abort"
                               id="confirmDeleteButton"/>
        </ice:form>

        <ice:form id="manageProjectForm" rendered="#{manageProjectController.validRequest and !manageProjectController.deleteRequest}" partialSubmit="true">

            <h1><ui:insert name="heading" /></h1>

            <div class="formSection">
                <ice:outputLabel value="#{form['label.name']}" for="inName"/>
                <ice:outputText value="#{form['constraint.required']}" styleClass="required" />
                <ice:inputText id="inName"
                               label="#{form['label.name']}"
                               maxlength="255"
                               value="#{manageProjectController.name}"
                               required="true"
                               validator="#{manageProjectController.checkProjectName}">
                    <f:validateLength minimum="3" maximum="50" />

                    <f:validator validatorId="RegexValidator" />
                    <f:attribute name="inputCharset" value="A-Za-z0-9-_" />
                </ice:inputText>
                <p>
                <ice:outputText value="#{form['constraint.minlength']}" nospan="true" /> 3;
                <ice:outputText value="#{form['constraint.maxlength']}" nospan="true" /> 50;
                <ice:outputText value="#{form['constraint.charset']}" nospan="true" /> [A-Za-z0-9-_];
                <ice:outputText value="#{form['constraint.projectname']}" nospan="true" />
                </p>
            </div>







            <div class="formSection">
                <ice:outputLabel value="#{form['label.description']}" for="inDescription"/>
                <ice:inputTextarea id="inDescription"
                                   label="#{form['label.description']}"
                                   maxlength="1000"
                                   value="#{manageProjectController.description}">
                    <f:validateLength maximum="1000" />
                </ice:inputTextarea>
                <p><ice:outputText value="#{form['constraint.maxlength']}" nospan="true" /> 1000</p>
            </div>





            <div class="formSection last">
                <ice:outputLabel value="#{form['label.members']}" for="inMember"/>

                <ice:inputText label="#{form['label.members']}"
                               id="inMember"
                               styleClass="add"
                               value="#{manageProjectController.memberInput}"
                               validator="#{manageProjectController.checkEmailAddress}"/>

                <ice:commandButton actionListener="#{manageProjectController.addMember}"
                                   value="#{form['button.add']}"
                                   styleClass="confirm add"
                                   id="inMemberAdd"/>

                <p style="padding-top: 5px"><ice:outputText value="#{form['project.manage.help.enter']}" nospan="true" /></p>

                <ice:dataTable value="#{manageProjectController.projectMembers}" var="item" styleClass="memberSelect">
                    <ice:column>
                        <f:facet name="header">
                            <ice:outputText value="#{manageProjectController.currentUser.person.name}" nospan="true"/>
                            <span>&lt;<ice:outputText value="#{manageProjectController.currentUser.person.email}" nospan="true"/>&gt;</span>
                        </f:facet>
                        <ice:outputText value="#{item.person.name}" nospan="true"/>
                        <span>&lt;<ice:outputText value="#{item.person.email}" nospan="true"/>&gt;</span>
                    </ice:column>
                    <ice:column>
                        <f:facet name="header">
                            <a name="#{manageProjectController.getRole(manageProjectController.currentUser.person.id)}"
                               class="preselectValue" />
                            <ice:selectOneListbox size="1"
                                                  valueChangeListener="#{manageProjectController.roleChanged}">
                                <f:selectItems value="#{manageProjectController.getRoles(manageProjectController.currentUser.person.id)}" />
                            </ice:selectOneListbox>

                        </f:facet>
                        <a name="#{manageProjectController.getRole(item.person.id)}"
                           class="preselectValue" />
                        <ice:selectOneListbox size="1"
                                              valueChangeListener="#{manageProjectController.roleChanged}">
                            <f:selectItems value="#{manageProjectController.getRoles(item.person.id)}" />
                        </ice:selectOneListbox>
                    </ice:column>
                    <ice:column styleClass="navigationColumn">
                        <f:facet name="header" />
                        <ice:commandLink value=""
                                         actionListener="#{manageProjectController.removeMember}"
                                         immediate="true"
                                         styleClass="columnNavigationLink">
                            <img alt="#{form['project.manage.remove.member']}"
                                 src="resources/images/removeSmall.png"
                                 width="14"
                                 height="14"/>
                            <f:attribute value="#{item}" name="member" />
                        </ice:commandLink>
                    </ice:column>
                </ice:dataTable>

                <p class="lineSpacer" />
            </div>









            <ice:commandButton action="#{manageProjectController.submitForm}"
                               value="#{form['button.submit']}"
                               styleClass="confirm"
                               id="manageProjectCreateButton"/>



            <ice:commandButton actionListener="#{manageProjectController.resetForm}"
                               value="#{form['button.clear']}"
                               styleClass="abort"
                               immediate="true"/>

        </ice:form>
    </ui:define>

    <ui:define name="sidebar">
        <ui:insert name="sidebar" />
    </ui:define>
</ui:composition>